package wang.conge.javasedemo.core.thread;

import java.util.Date;

public class WaitAndNotifyDemo{

    public static void main(String[] args){
    	Object mike = new Object();
        
    	new Thread(new TalkRunable("kaka", mike)).start();
    	new Thread(new TalkRunable("cluo", mike)).start();
    	new Thread(new TalkRunable("messi", mike)).start();
    }
    
    static class TalkRunable implements Runnable{
    	private String name;
    	private Object mike;
    	
    	public TalkRunable(String name , Object mike){
    		this.name = name;
    		this.mike = mike;
    	}
    	
		@Override
		public void run() {
			while(true){
				synchronized (mike) {
					System.out.println(name + (new Date()));
					
					mike.notifyAll();
					
					try {
						mike.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}
    	
    }
}